import Taro, { Component } from '@tarojs/taro'
import { View, Image, Text } from '@tarojs/components'
import { AtButton, } from 'taro-ui'
import { DNavBar } from '@/components'
import http from '@/api'
import './index.scss'

export default class EntEmployeeDetail extends Component {
    state = {
        inreviewIcon: require('../../../assets/images/icon／审核中@2x.png'),
        verifiedIcon: require('../../../assets/images/icon／已认证@2x.png'),
        refusedIcon: require('../../../assets/images/icon／被拒绝@2x.png'),
        reomveIcon: require('../../../assets/images/icon／被移除@2x.png'),
        employeeApplyInfo: '',
        userInfo: ''
    }

    componentDidShow() {
        this.init()
    }

    init() {
        this.getEmpApproInfo()
        this.getUserInfo()
    }

    async getEmpApproInfo() {
        let employeeApplyInfo = await http.getEmpApproInfo()

        this.setState({
            employeeApplyInfo
        })
    }

    async getUserInfo() {
        let userInfo = await http.myselfDetail()
        this.setState({
            userInfo,
        })
    }

    filterApplyStatus() {
        let { userInfo , inreviewIcon, verifiedIcon, refusedIcon, reomveIcon } = this.state
        switch (userInfo.imIsAppro) {
            case '0': // 待审核
                return {
                    text: '待审核',
                    icon: inreviewIcon
                }
            case '1': // 审核通过
                return {
                    text: '已认证',
                    icon: verifiedIcon
                }
            case '2': // 被拒绝
                return {
                    text: '被拒绝',
                    icon: refusedIcon
                }
            case '3': // 被移除
                return {
                    text: '审核通过',
                    icon: reomveIcon
                }
            default:
                break;
        }
    }


    render() {
        const { employeeApplyInfo, userInfo } = this.state

        return (
            <View className="entemployee_detail">
                <DNavBar title="企业认证详情"></DNavBar>
                <View className="container">
                    <View className="entinfo">
                        <View className="info_item">
                            <Text className="info_item_label">企业名称</Text>
                            <Text className="info_item_value">{employeeApplyInfo.entName}</Text>
                        </View>
                        <View className="info_item">
                            <Text className="info_item_label">企业管理员</Text>
                            <Text className="info_item_value">{employeeApplyInfo.updator}</Text>
                        </View>
                        <View className="info_item">
                            <Text className="info_item_label">认证方式</Text>
                            <Text className="info_item_value">企业员工认证</Text>
                        </View>
                        <View className="info_item">
                            <Text className="info_item_label">认证提交时间</Text>
                            <Text className="info_item_value">{employeeApplyInfo.createTime}</Text>
                        </View>
                        <View className="info_item">
                            <Text className="info_item_label">审核状态</Text>
                            <Text className="info_item_value">{userInfo && this.filterApplyStatus.bind(this)().text}</Text>
                        </View>
                        {
                            userInfo.imIsAppro == 3 && <View className="info_item">
                                <Text className="info_item_label">当前状态</Text>
                                <Text className="info_item_value">已被企业移除</Text>
                            </View>
                        }
                        {
                            userInfo.imIsAppro == 3 && <View className="info_item">
                                <Text className="info_item_label">移除时间</Text>
                                <Text className="info_item_value">{employeeApplyInfo.updateTime}</Text>
                            </View>
                        }
                        <Image className="apply_status_img" src={userInfo && this.filterApplyStatus.bind(this)().icon}></Image>
                    </View>

                    {
                        (userInfo.imIsAppro == 3 || userInfo.imIsAppro == 2) && <AtButton className="btn" onClick={() => {
                            Taro.navigateTo({
                                url: '/pages/myinfo/enterprisecert'
                            })
                        }}>重新认证</AtButton>
                    }
                </View>
            </View>
        )
    }
}
